<?php
/* @var $this PropertyController */
/* @var $model Property */
/* @var $data Amenity */
/* @var $amenity_value AmenityValue */


/* @var $form CActiveForm */
?>

<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'property-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // There is a call to performAjaxValidation() commented in generated controller code.
        // See class documentation of CActiveForm for details on this.
        'enableAjaxValidation' => false,
        'htmlOptions' => array('role' => "form", 'enctype' => 'multipart/form-data')
    ));
    ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

        <?php echo $form->errorSummary($model); ?>
    <div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save', array('class' => 'btn btn-primary btn-small pull-right')); ?>
    </div>           
    <!-- Nav tabs -->
    <ul class="nav nav-tabs">
        <li class="active"><a href="#General" data-toggle="tab">General</a></li>
        <li><a href="#Location" data-toggle="tab">Location</a></li>
        <li><a href="#Addition" data-toggle="tab">Addition</a></li>
        <li><a href="#Photos" data-toggle="tab">Photos/Videos</a></li>
        <li><a href="#Seo" data-toggle="tab">Seo</a></li>
        <li id="mapTab"><a href="#Map" data-toggle="tab">Map</a></li>
        <li><a href="#Agent" data-toggle="tab">Agent</a></li>
        <li><a href="#Admin" data-toggle="tab">Administration</a></li>
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div class="tab-pane active" id="General">

            <div class="form-group">
                <?php echo $form->labelEx($model, 'name'); ?>
<?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 255, 'class' => "form-control")); ?>
<?php echo $form->error($model, 'name'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'type'); ?>
<?php echo $form->dropDownList($model, 'type', Settings::getValueByKey("property_types"), array('class' => "form-control")); ?>
<?php echo $form->error($model, 'type'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'category'); ?>
<?php echo $form->dropDownList($model, 'category', Settings::getValueByKey("property_categories"), array('class' => "form-control")); ?>
                <?php echo $form->error($model, 'category'); ?>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($model, 'phone'); ?>
<?php echo $form->textField($model, 'phone', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'phone'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'description'); ?>
<?php echo $form->textArea($model, 'description', array('rows' => 6, 'class' => "form-control")); ?>
<?php echo $form->error($model, 'description'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'price'); ?>
<?php echo $form->textField($model, 'price', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'price'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'number_of_rooms'); ?>
<?php echo $form->textField($model, 'number_of_rooms', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'number_of_rooms'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'number_of_bedrooms'); ?>
<?php echo $form->textField($model, 'number_of_bedrooms', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'number_of_bedrooms'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'number_of_bathrooms'); ?>
<?php echo $form->textField($model, 'number_of_bathrooms', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'number_of_bathrooms'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'floor'); ?>
<?php echo $form->textField($model, 'floor', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'floor'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'total_floor'); ?>
<?php echo $form->textField($model, 'total_floor', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'total_floor'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'square'); ?>
<?php echo $form->textField($model, 'square', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'square'); ?>
            </div>


        </div>
        <div class="tab-pane" id="Location" >
            <div class="form-group">
                <?php echo $form->labelEx($model, 'country'); ?>
<?php echo $form->textField($model, 'country', array('size' => 45, 'maxlength' => 45, 'class' => 'form-control')); ?>
<?php echo $form->error($model, 'country'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'city'); ?>
<?php echo $form->textField($model, 'city', array('size' => 45, 'maxlength' => 45, 'class' => "form-control")); ?>
<?php echo $form->error($model, 'city'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'area'); ?>
<?php echo $form->textField($model, 'area', array('size' => 45, 'maxlength' => 45, 'class' => "form-control")); ?>
<?php echo $form->error($model, 'area'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'street_address'); ?>
<?php echo $form->textArea($model, 'street_address', array('rows' => 6, 'cols' => 50, 'class' => "form-control")); ?>
<?php echo $form->error($model, 'street_address'); ?>
            </div>



        </div> 
        <div class="tab-pane" id="Addition">


            <div class="form-group">
			
			
		<?php
$data = Amenity::model()->findAllbySql('Select id, title from Amenity');
foreach ($data as $record){

  
 	

     ?>
	 <div class="row-md-3">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><?php echo $record['title']?></h3>
<?php
$amenid=$record['id'];


 echo CHtml::checkBoxList('checkBoxList','',
    CHtml::listData(AmenityValue::model()->findAllbySql('Select value from amenity_value where amenity_id = '.$amenid), 'amenity_id', 'value'),array('amenity_id'=>'checkboxlist','value'=>'checkboxlist',
           )
);


?>		</div>
				
 

 
                

             
           
        </div>
    </div>

			
	<?php }?>	
           
			</div></div>

        <div class="tab-pane" id="Photos"><div class="form-group">
                <?php echo $form->labelEx($model, 'main_photo'); ?>
<?php echo $form->fileField($model, 'main_photo', array('size' => 45, 'maxlength' => 45)); ?>
<?php echo $form->error($model, 'main_photo'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'photo_1'); ?>
<?php echo $form->fileField($model, 'photo_1', array('size' => 45, 'maxlength' => 45)); ?>
<?php echo $form->error($model, 'photo_1'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'photo_2'); ?>
<?php echo $form->fileField($model, 'photo_2', array('size' => 45, 'maxlength' => 45)); ?>
<?php echo $form->error($model, 'photo_2'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'photo_3'); ?>
<?php echo $form->fileField($model, 'photo_3', array('size' => 45, 'maxlength' => 45)); ?>
<?php echo $form->error($model, 'photo_3'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'photo_4'); ?>
<?php echo $form->fileField($model, 'photo_4', array('size' => 45, 'maxlength' => 45)); ?>
<?php echo $form->error($model, 'photo_4'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'video'); ?>
<?php echo $form->fileField($model, 'video', array('size' => 45, 'maxlength' => 45)); ?>
<?php echo $form->error($model, 'video'); ?>
            </div>
        </div>
        <div class="tab-pane" id="Seo">
            <div class="form-group">
                <?php echo $form->labelEx($model, 'url'); ?>
<?php echo $form->textField($model, 'url', array('class' => "form-control")); ?>
                <?php echo $form->error($model, 'url'); ?>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($model, 'meta_description'); ?>
<?php echo $form->textField($model, 'meta_description', array('size' => 60, 'maxlength' => 255, 'class' => "form-control")); ?>
<?php echo $form->error($model, 'meta_description'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'meta_keywords'); ?>
<?php echo $form->textArea($model, 'meta_keywords', array('rows' => 6, 'cols' => 50, 'class' => "form-control")); ?>
<?php echo $form->error($model, 'meta_keywords'); ?>
            </div>
        </div>
        <div class="tab-pane" id="Map">
            <?php
            Yii::app()->clientScript->registerScriptFile("https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false", CClientScript::POS_HEAD);

            Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/gmap3.min.js', CClientScript::POS_HEAD);
            ?>

            <div id="map_canvas">

            </div>

            <script>
                //          $("#map_canvas").gmap3({
                //  getlatlng:{
                //    address: "<?php echo $model->street_address . ',' . $model->city ?>",
                //    callback: function(results){
                //      if ( !results ) return;
                //      console.log(results[0].geometry.location);
                //var i = 0;
                //                $.each(results[0].geometry.location, function(index, value) {
                //                    if(i == 0) { lat = value; }
                //                    if(i == 1) { lng = value; }
                //                    i++;
                //                });
                //      $("#Property_lat").val(lat);
                //      $("#Property_lng").val(lng);
                //      $(this).gmap3({
                //        marker:{
                //          latLng:results[0].geometry.location,
                //        },
                //         map:{
                //      options:{
                //        zoom: 15,
                //        mapTypeId: google.maps.MapTypeId.ROADMAP,
                //        center:new google.maps.LatLng(lat, lng),
                //      }
                //      //action: 'setCenter', args:[ results[0].geometry.location ]
                //      
                //      
                //    }
                //
                //      }
                //  );
                //    
                // 
                //    }
                //  }
                //  
                //});
                //$("#mapTab").click(function(){
                //
                //setTimeout(function(){
                //
                //  $('#map_canvas')
                //    .gmap3({trigger:"resize"});
                //    console.log($("#Property_lat").val(lat),$("#Property_lng").val(lng));
                //    $("#map_canvas").setCenter(new google.maps.LatLng($("#Property_lat").val(lat),$("#Property_lng").val(lng)));
                //    },2000);
                //
                //    
                //});


                var geocoder;
                var map;
                var maker;
                function initialize() {
                    geocoder = new google.maps.Geocoder();
                    var latlng = new google.maps.LatLng(-34.397, 150.644);
                    var mapOptions = {
                        zoom: 15,
                        center: latlng,
                        streetViewControl: false
                    }
                    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
                }
                
                function getAddress(){
                var address="";    
                
        if(!$("#Property_street_address").val()=="")
            address=address+$("#Property_street_address").val();
        if(!$("#Property_area").val()=="")
            address=address+","+$("#Property_area").val();
        if(!$("#Property_city").val()=="")
            address=address+","+$("#Property_city").val();
        console.log(address);
        return address;
                }
                
                function setLatlng(res){
                    var i=0;
                    $.each(res, function(index, value) {
                                    if(i == 0) { lat = value; }
                                    if(i == 1) { lng = value; }
                                    i++;
                                });
                      $("#Property_lat").val(lat);
                      $("#Property_lng").val(lng);
                }

                function codeAddress() {
                    var address = getAddress();//document.getElementById("address").value;
                    geocoder.geocode({'address': address}, function(results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            map.setCenter(results[0].geometry.location);
                            setLatlng(results[0].geometry.location);
                            console.log(results[0].geometry.location);
                            marker = new google.maps.Marker({
                                map: map,
                                position: results[0].geometry.location
                            });
                        } else {
                            alert("Geocode was not successful for the following reason: " + status);
                        }
                    });
                }
                //  google.maps.event.addDomListener(window, 'load', initialize);
                //google.maps.event.addDomListener(window, 'resize', initialize);
                google.maps.event.addDomListener(window, 'load', initialize);
                $("#mapTab").click(function() {

                    //     initialize(); 
                    codeAddress();
                    setTimeout(function() {
                        google.maps.event.trigger(map, "resize");
                        map.setCenter(marker.getPosition());
                        console.log(marker.getPosition());
                    }, 1000);
                });

            </script>
            <div class="form-group">
                <?php echo $form->labelEx($model, 'lat'); ?>
<?php echo $form->textField($model, 'lat', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'lat'); ?>
            </div>

            <div class="form-group">
                <?php echo $form->labelEx($model, 'lng'); ?>
<?php echo $form->textField($model, 'lng', array('class' => "form-control")); ?>
<?php echo $form->error($model, 'lng'); ?>
            </div></div>
        <div class="tab-pane active" id="Agent">
            <div class="form-group">
                <?php echo $form->labelEx($model, 'agent_id'); ?>
<?php echo $form->textField($model, 'agent_id'); ?>
<?php echo $form->error($model, 'agent_id'); ?>
            </div>

        </div>
        <div class="tab-pane active" id="Admin">
            <div class="form-group">
                <?php echo $form->labelEx($model, 'status'); ?>
<?php echo $form->dropdownList($model, 'status', array('1' => 'Active', '0' => 'Inactive'), array('class' => "form-control")); ?>
<?php echo $form->error($model, 'status'); ?>
            </div>


            <div class="form-group">
                <?php echo $form->labelEx($model, 'feature'); ?>
<?php echo $form->checkbox($model, 'feature'); ?>
<?php echo $form->error($model, 'feature'); ?>
            </div>

        </div>
    </div>

    <div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save', array('class' => 'btn btn-primary btn-small pull-right')); ?>
    </div>

<?php $this->endWidget(); ?>

</div><!-- form -->